Skip to content

accept attachment name or url to get addon config #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025

Conversation

ekozilforce
Copy link
Collaborator

@ekozilforce ekozilforce commented May 8, 2025

Description

This pr renames getConnection -> getAuthorization it to accept a url or attachment name to resolve addon config.

Some other small changes as per https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00002C13J3YAJ/view:

  • update the authorization requests to send a developer_name instead of org_name

Todo

  • Change auth request from POST to GET: GET /addons/${addon_uuid}/authorizations/${developer_name_or_id}
  • Handle response format change
  • Test e2e

* @returns Org
*/
export async function getConnection(name: string): Promise<Org> {
export async function getAuthorization(name: string, attachmentNameOrUrl = "APPLINK"): Promise<Org> {
Copy link
Collaborator Author

@ekozilforce ekozilforce May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the param name become developer_name_or_id? It looks like the auth endpoint may accept either, considering the requested change:

From POST to GET: GET /addons/${addon_uuid}/authorizations/${developer_name_or_id}

@@ -29,7 +29,7 @@ fastify.get('/accounts', async function (request, reply) {
const applinkAddon = request.sdk.addons.applink;

logger.info(`Getting org '${orgName}' connection from Heroku Applink add-on...`);
const anotherOrg = await applinkAddon.getConnection(orgName);
const anotherOrg = await applinkAddon.getAuthorization(orgName);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to rethink the example a bit here given the change to use a developer name instead of org name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree. Best to be consistent.

@ekozilforce ekozilforce force-pushed the ekozil/add-attachment-or-url-scoped-authorizations branch from 7281237 to ce169a4 Compare May 8, 2025 15:29
Copy link
Collaborator

@cwallsfdc cwallsfdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Plus GET per WI update.

@@ -29,7 +29,7 @@ fastify.get('/accounts', async function (request, reply) {
const applinkAddon = request.sdk.addons.applink;

logger.info(`Getting org '${orgName}' connection from Heroku Applink add-on...`);
const anotherOrg = await applinkAddon.getConnection(orgName);
const anotherOrg = await applinkAddon.getAuthorization(orgName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree. Best to be consistent.


const HTTP_REQUEST = new HttpRequestUtil();

/**
* Get stored Salesforce or Data Cloud org user credentials for given name or alias.
* @param name or alias
* @param attachmentNameOrUrl Either an attachment name (e.g. "APPLINK") or a full URL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. "APPLINK" -> e.g. "HEROKU_APPLINK"? Or, since that's the default, e.g. "MYNAME", e.g. "IVORY"? Should we say it defaults to "HEROKU_APPLINK".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should be HEROKU_APPLINK since that's the default attachment iirc.

export async function getConnection(name: string): Promise<Org> {
export async function getAuthorization(
name: string,
attachmentNameOrUrl = "APPLINK"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HEROKU_APPLINK?

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025. Favor: update date everywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll handle that in a separate pr to avoid noise.

export async function getAuthorization(
name: string,
attachmentNameOrUrl = "APPLINK"
): Promise<Org> {
if (!name) {
throw Error(`Connection name not provided`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developer name.

import {
resolveAddonConfigByAttachment,
resolveAddonConfigByUrl,
} from "~/utils/addon-config";

const HTTP_REQUEST = new HttpRequestUtil();

/**
* Get stored Salesforce or Data Cloud org user credentials for given name or alias.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given developer name.

export async function getAuthorization(
name: string,
attachmentNameOrUrl = "APPLINK"
): Promise<Org> {
if (!name) {
throw Error(`Connection name not provided`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developer name.

// Look for corresponding token
const token = process.env[`${prefix}_TOKEN`];
if (!token) {
throw Error(`Heroku Applink config not found for API URL: ${url}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Token not found?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feelings here right now. I can change to reference the missing token config var explicitly.

@ekozilforce ekozilforce force-pushed the ekozil/add-attachment-or-url-scoped-authorizations branch from cdb2ad6 to 6ae41dc Compare May 13, 2025 19:41
@ekozilforce ekozilforce merged commit 6ae41dc into main May 14, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants